<?php

namespace App\Http\Controllers\Api\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Notice;
use App\Http\Requests\Api\ApiRequest;
use DB;

class NoticeController extends Controller
{
    public function index(ApiRequest $request)
    {
    	$data = DB::table('notice_user as num')
                ->leftJoin('notices as n','n.id','=','nu.notice_id')->select(['n.*','nu.is_read'])
                ->paginate(10);
    	
    	if($data) {
    		$rs['status'] = true;
    		$rs['data'] = $data;
    	}
    	return response()->json($rs);    	
    }

    public function show(ApiRequest $request)
    {
        $id = $request->id; 
        $data = Notice::find($id);
        if($data) {
            $rs['status'] = true;
            $rs['data'] = $data;
        }
        return response()->json($rs);       
    }
}
